/* 
    file:   ui_button.c
 */
/* ------------------------------------------------------------------------- */
#include "ui_button.h"
#include "stm32f7_ltdc.h"

ui_style_t ui_button_def=
{
    .body=
    {
        .main_color = 0x0000,
        .grad_color = 0xff00,
        .radius = 0,
        .opa = 0xff,
    },
    .text=
    {
        0
    }
};
uint8_t ui_button_sc(struct ui_obj * obj, uint8_t sign, void * param)
{

    int sx = 0;
    int sy = 0;
    point realpoint;
    struct ui_core * pcore = NULL;
    if(param)
    {
        pcore = (struct ui_core *)param;
    }


    ui_getlct(obj,&realpoint);
    sx = obj->area.x2-obj->area.x1;
    sy = obj->area.y2-obj->area.y1;

    if(sign == ui_signal_init_r)
    {
        DRAMFill(pcore->pscr->pbfa,realpoint.x,realpoint.y,realpoint.x+sx,realpoint.y+sy,0x0ff0);
    }
    if(sign == ui_signal_releassed)
    {
        DRAMFill(pcore->pscr->pbfa,realpoint.x,realpoint.y,realpoint.x+sx,realpoint.y+sy,0x00ff);
    }
    if(sign == ui_signal_pressing)
    {
        DRAMFill(pcore->pscr->pbfa,realpoint.x,realpoint.y,realpoint.x+sx,realpoint.y+sy,0xff00);
    }
    if(sign == ui_signal_pressed)
    {
        DRAMFill(pcore->pscr->pbfa,realpoint.x,realpoint.y,realpoint.x+sx,realpoint.y+sy,0xff00);
    }
    
    return 0;
}
struct ui_obj * ui_newobutton(struct ui_obj * ppar)
{
    struct ui_obj * pnewobj = NULL;
    pnewobj = ui_newobj(ppar);

    pnewobj->signal_cb = ui_button_sc;
    pnewobj->touch = 1;
    return pnewobj;
}

